using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using Auto.Data.Security;
using BLL = Auto.Data.Systems.BLL;
using Model = Auto.Data.Systems.Model;
using Auto.Data.Setting;
using Auto.Web.Common;
using BaseSystem._System;

namespace BaseSystem.DemoPage
{

    public partial class Trees : System.Web.UI.Page
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.UcTrees1.OperationClick += new BaseSystem._System.UserControl.ucTrees.OperationClickEventHandler(OperationClick);
        }
        protected void OperationClick(string operation,string type)
        {
            Response.Write("operation:" + operation + " type:" + type);
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            //this.UcTrees1.IsGetParentValue = true;
        
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                IDictionary<string, string> contextMenu = new Dictionary<string, string>();
                contextMenu.Add("add", "add value");
                contextMenu.Add("modify", "modify value");

                this.UcTrees1.ContextMenu = contextMenu;

                this.txtSystemID.Text = "_System";
                this.txtRoleID.Text = "BaseSystemRole ID:";
                InitPage();

                SysRoles sysRoles = new SysRoles();

                //this.UcTrees2.SetTreesData(sysRoles.GetSystemsAndRoles(), Systems.FIELD_SysID, Systems.FIELD_SysName, "", SysRoles.FIELD_RoleID, SysRoles.FIELD_RoleName);
                //this.UcTrees2.TreeInit();
            }
        }

        #region Init Page
        private void InitPage()
        {

            SysRoles sysRoles = new SysRoles();
            DataTable dt = sysRoles.GetSystemsAndFunc(SessionBox.CultrueInfo);
            this.UcTrees1.SetTreesData(dt, Systems.FIELD_SysID, Systems.FIELD_SysName, Model.SysFunctions.FIELD_ParentID, Model.SysFunctions.FIELD_FuncID, Model.SysFunctions.FIELD_FuncName);
            this.UcTrees1.TreeInit();
        }
        #endregion Init Page

        protected void btnSetValue_Click(object sender, EventArgs e)
        {
            SysRoles sysRoles = new SysRoles();
            this.UcTrees1.SetTreesData(sysRoles.GetRoleFunc(this.txtSystemID.Text, this.txtRoleID.Text), Model.SysFunctions.FIELD_Path, Model.SysFunctions.FIELD_SysID, Model.SysFunctions.FIELD_ParentID, Model.SysFunctions.FIELD_FuncID, "");
            this.UcTrees1.SetCheckedValue();

            UsersRoles userRoles = new UsersRoles();
            //this.UcTrees2.SetTreesData(userRoles.GetDataByKey("", "", "admin1"), UsersRoles.FIELD_SysID, "", "", UsersRoles.FIELD_RoleID, "");
            //this.UcTrees2.SetCheckedValue();
        }

        protected void btnGetValue_Click(object sender, EventArgs e)
        {
            IDictionary<string, string> result = this.UcTrees1.GetCheckedNodes;
            foreach (KeyValuePair<string, string> keyValue in result)
            {
                Response.Write(keyValue.Key + "," + keyValue.Value + "<BR>");
            }
        }
    }
}
